//
//  HomeRmdSectionTwoCell.m
//  copyrightTrading
//
//  Created by edz on 2020/10/9.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "HomeRmdSectionTwoCell.h"
#import "HomeRmdSectionTwoSubCell.h"
@interface HomeRmdSectionTwoCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *stateCollectionView; // 模式列表

@end

@implementation HomeRmdSectionTwoCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = RGB_VALUE(0xF5F5F5);
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    UIView *bgView = [UIView new];
    bgView.backgroundColor = RGB_VALUE(0xFFFFFF);
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.bottom.offset(-4);
    }];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.sectionInset = UIEdgeInsetsMake(0, 17, 0, 17);
    layout.minimumLineSpacing = 7;
    layout.minimumInteritemSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.stateCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    self.stateCollectionView.delegate = self;
    self.stateCollectionView.dataSource = self;
    self.stateCollectionView.backgroundColor = RGB_VALUE(0xFFFFFF);
//    self.stateCollectionView.backgroundColor = UIColor.clearColor;
    self.stateCollectionView.showsHorizontalScrollIndicator = NO;
    [self.stateCollectionView registerClass:[HomeRmdSectionTwoSubCell class] forCellWithReuseIdentifier:@"HomeRmdSectionTwoSubCell"];
    [self.contentView addSubview:self.stateCollectionView];
    [self.stateCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.height.mas_equalTo(99);
    }];
}

- (void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    [self.stateCollectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(166, 99);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomeRmdSectionTwoSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeRmdSectionTwoSubCell" forIndexPath:indexPath];
    cell.dataDic = self.dataArray[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(tapSectionTwoCellWithData:)]) {
        [self.delegate tapSectionTwoCellWithData:self.dataArray[indexPath.row]];
    }
}
@end
